<?php

/**
 * LEAGUEMan
 * 
 * Copyright (C) 2007 Marko Bischof
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

require_once 'Savant2/Plugin.php';

class Savant2_Plugin_leagueman_show_roundresult extends Savant2_Plugin{
	
	function plugin($matches, $options){
		
		ob_start();  
?>
			<table width="100%" align="center">
<?php
			$k = 0;
			$match_date = "";
			foreach($matches as $match){
			
				$class = ($k == 0)? 'sectiontableentry1' : 'sectiontableentry2';
			
				$home = $options["names"] == "short" ? $match->team1_name_short : $match->team1_name;
				$away = $options["names"] == "short" ? $match->team2_name_short : $match->team2_name;
				
				$r1 = (is_numeric($match->match_result_0_1) && is_numeric($match->match_result_0_2) ) ? sprintf("%s:%s",   $match->match_result_0_1, $match->match_result_0_2) : "-:-";
				$r2 = (is_numeric($match->match_result_1_1) && is_numeric($match->match_result_1_2) ) ? sprintf("(%s:%s)", $match->match_result_1_1, $match->match_result_1_2) : "&nbsp;";
			
				
				if($match->match_team1 == $options["favteam"]){
					$home = "<strong>{$home}</strong>";
				}
				
				if($match->match_team2 == $options["favteam"]){
					$away = "<strong>{$away}</strong>";
				}
				
				if($options["showmatchdate"]){
					if($match_date != $match->match_date){
						$match_date = $match->match_date;
?>
						<tr>
							<td class="sectiontableheader" colspan="5"><?php echo mosFormatDate($match_date . " " . $match->match_time, $options["matchdateformat"]);?></td>
						</tr>
<?php
					}
				}
?>
				<tr>
					<td width="45%" class="<?php echo $class;?>"><div align="right"><?php echo $home; ?>&nbsp;&nbsp;<?php $this->Savant->plugin("thumb", "logos", $match->team1_logo, 18, 18); ?></div></td>
					<td width="1%"  class="<?php echo $class;?>"><div align="center">-</div></td>
					<td width="45%" class="<?php echo $class;?>"><div align="left"><?php $this->Savant->plugin("thumb", "logos", $match->team2_logo, 18, 18); ?>&nbsp;&nbsp;<?php echo $away; ?></div></td>
					<td width="4%"  class="<?php echo $class;?>"><div align="center"><?php echo $r1; ?></div></td>
					<td width="5%"  class="<?php echo $class;?>"><div align="center"><?php echo $r2; ?></div></td>
				</tr>
<?php
				$k = 1 - $k;
			}
?>
			</table> 
<?php
			$html = ob_get_contents();
		ob_end_clean();
	
		return $html;
	}
}
?>